package com.itchu.system.mapper;


import com.itchu.system.domain.SysRole;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import com.itchu.system.common.BaseMapper;

import java.util.List;

public interface SysRoleMapper extends BaseMapper<SysRole> {

    // 根据角色id查找权限列表
    List<SysRole> findRolesByRid(Long id);

    // 根据角色id删除角色-用户中间表对应的记录
    void deleteUserIdRoleId(Long id);

    // 向角色-用户中间表添加记录
    void addUserIdRoleId(@Param("id") Long id, @Param("rids") List<Long> rids);

    @Select("SELECT * FROM sys_role INNER JOIN sys_user_role\n" +
            "ON id =  role_id \n" +
            "WHERE user_id = #{uid}")
    @Results({
            @Result(id = true,property = "id",column = "id"),
            @Result(property = "roleName", column = "role_name"),
            @Result(property = "description", column = "description"),
            @Result(property = "createTime", column = "create_time"),
            @Result(property = "updateTime", column = "update_time"),
    })
    List<SysRole> findByUid(Long uid);
}
